from django.conf.urls import url
from rest_framework.routers import DefaultRouter, SimpleRouter

from booktest import views
from booktest import views_old

urlpatterns = [
    # url(r"^books/$",views.BooksAPIView.as_view()),
    # url(r'^books/(?P<pk>\d+)/$', views.BookAPIView.as_view())
    # url(r'books/$', views.BooksAPIView.as_view())

    # 使用GenericAPIView实现获得所有和单一图书信息接口
    # url(r'^books/$', views.BookListView.as_view()),
    # url(r'^books/(?P<pk>\d+)/$', views.BookDetailView.as_view()),

    # 使用GenericViewSet实现获取所有或单一图书信息接口
    # url(r'^books/$', views.BookInfoViewSet.as_view({'get':'list'})),
    # url(r'^books/(?P<pk>\d+)/$', views.BookInfoViewSet.as_view({'get':'retrieve'})),

    # 使用GenericViewSet + mixins实现获取所有或单一图书信息接口
    # url(r'^books/$', views.BookInfoViewSet.as_view({'get':'list', 'post':'create'})),
    # url(r'^books/(?P<pk>\d+)/$', views.BookInfoViewSet.as_view({'get':'retrieve'})),

    # url(r'^books/latest/$', views.BookInfoViewSet.as_view({'get':'latest'})),
    # url(r'^books/(?P<pk>\d+)/read/$', views.BookInfoViewSet.as_view({'put': 'read'})),
]



# 创建路由器
# router = SimpleRouter()
router = DefaultRouter()
router.register(r'books', views.BookInfoViewSet)
urlpatterns += router.urls
print(router.urls)



"""
[<RegexURLPattern bookinfo-list ^books/$>,
<RegexURLPattern bookinfo-list ^books\.(?P<format>[a-z0-9]+)/?$>,
<RegexURLPattern bookinfo-latest ^books/latest/$>,
<RegexURLPattern bookinfo-latest ^books/latest\.(?P<format>[a-z0-9]+)/?$>,
<RegexURLPattern bookinfo-detail ^books/(?P<pk>[^/.]+)/$>,
<RegexURLPattern bookinfo-detail ^books/(?P<pk>[^/.]+)\.(?P<format>[a-z0-9]+)/?$>,
<RegexURLPattern bookinfo-read ^books/(?P<pk>[^/.]+)/read/$>,
<RegexURLPattern bookinfo-read ^books/(?P<pk>[^/.]+)/read\.(?P<format>[a-z0-9]+)/?$>,
<RegexURLPattern api-root ^$>, <RegexURLPattern api-root ^\.(?P<format>[a-z0-9]+)/?$>]


"""